package Demo3_8;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User：Lenovo
 * Date:2025-03-08
 * Time:22:43
 */
import java.util.HashMap;
import java.util.Map;

public class MapTraversal {
    public static void main(String[] args) {
        Map<String, Integer> scores = new HashMap<>();
        scores.put("Alice", 85);
        scores.put("Bob", 90);
        scores.put("Charlie", 78);

        // 遍历键
        System.out.println("遍历键:");
        for (String name : scores.keySet()) {
            System.out.println(name + ": " + scores.get(name));
        }

        // 遍历值
        System.out.println("遍历值:");
        for (int score : scores.values()) {
            System.out.println(score);
        }

        // 遍历键值对
        System.out.println("遍历键值对:");
        for (Map.Entry<String, Integer> entry : scores.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }
}    